﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DTO;
using BUS;

namespace TVC_WEB.UserControl
{
    public partial class Category : System.Web.UI.UserControl
    {
        CategoriesControl cateControl = new CategoriesControl();
        string sErr = "";
        public String htmlmenu = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            htmlmenu = TableMenu();
        }

        public string TableMenu()
        {
            string kq = "";


            DataTable dtMenu = cateControl.GetRootsCategories("Category", ref sErr);

            if (dtMenu.Rows.Count > 0)
            {

                for (int i = 0; i < dtMenu.Rows.Count; i++)
                {
                    CategoriesInfo cate = new CategoriesInfo(dtMenu.Rows[i]);
                    String classcolum = CheckSubMenu(cate.ID);
                    kq += "<li id=\"menu" + i + "\" class=\"Menuleft " + classcolum + "\" onmouseout=\"ShowSubMenu('menu" + i + "')\" onmouseover=\"ShowSubMenu('menu" + i + "')\">";

                    kq += "<a name=\"" + cate.NameVN + "\" title=\"" + cate.NameVN + "\" href=\"/Global/prolist.aspx?cate=" + cate.ID + "&catetype=" + cate.Type + "\">" + cate.NameVN + "</a>";
                    kq += GetSubMenu(cate, classcolum);
                    kq += "</li>";
                }
                kq += "</div>";
            }
            return kq;
        }

        public String CheckSubMenu(int ipare)
        {
            string kq = "";
            DataTable dt = cateControl.get_childs(ipare, ref sErr);
            if (dt.Rows.Count < 10)
                kq += "oneColumn";
            else if (dt.Rows.Count < 20)
                kq += "twoColumn";
            else if (dt.Rows.Count < 30)
                kq += "threeColumn";
            else if (dt.Rows.Count <= 40)
                kq += "fourColumn";

            return kq;
        }

        public String GetSubMenu(CategoriesInfo cate, string classcolum)
        {
            string kq = "";
            DataTable dt = cateControl.get_childs(cate.ID, ref sErr);
            if (dt.Rows.Count > 0)
            {
                kq += "<div class=\"grpMenu hidden\"> <div class=\"menuleftNav\">";
                kq += "<a name=\"" + cate.NameVN + "\" title=\"" + cate.NameVN + "\" href=\"/Global/prolist.aspx?cate=" + cate.ID + "&catetype=" + cate.Type + "\">" + cate.NameVN + "</a>";
                kq += "</div>";
                kq += " <div class=\"SubmenuleftNav\" >";
                kq += "<div class=\"wrap_content\">";
                kq += GetAllSub(dt);
                kq += "</div>";
                kq += "</div>";
                kq += "</div>";
            }

            return kq;
        }

        public String GetAllSub(DataTable dt)
        {
            String kq = "";

            kq += "<p class=\"column1\">";

            int i = 0;
            foreach (DataRow row in dt.Rows)
            {
                CategoriesInfo cate = new CategoriesInfo(dt.Rows[i]);
                if (i >= 10)
                {
                    kq += "</p><p class=\"column2\">";
                }
                else if (i >= 20)
                {
                    kq += "</p><p class=\"column3\">";
                }
                else if (i >= 30)
                {
                    kq += "</p><p class=\"column4\">";
                }
                kq += "<a class=\"tier3\" name=\"" + cate.NameVN + "\" title=\"" + cate.NameVN + "\" href=\"/Global/prolist.aspx?cate=" + cate.ID + "&catetype=" + cate.Type + "\">";
                kq += "<span class=\"title\">" + cate.NameVN + "</span>";
                kq += "<span class=\"info\"></span>";
                kq += "</a>";
                //     kq += "</p>";
                i++;
            }
            kq += "</p>";
            return kq;
        }
    }
}